import {FrontArticle} from "@/services";
import {ReactNode} from "react";


/**
 * 获取语言对应的值
 */
export const correspVal =<T extends any> (isZhCN?: boolean, cnVal?: T, enVal?: T) => {
  const val = isZhCN ? cnVal : enVal;
  return val || cnVal || enVal || undefined;
}

/**
 * 文章所以在的位置 (期刊,卷(期):页码)
 */
export const getArticleLocationStr = (article?: FrontArticle) => {
  let locationStr = `${article?.articleYear}`;
  if (article?.articleVolume) {
    locationStr += `,${article?.articleVolume}`;
  }
  if (article?.articlePeriod) {
    locationStr += `(${article?.articlePeriod})`;
  }
  if (article?.articleStartpage) {
    locationStr += `:${article?.articleStartpage}-${article?.articleEndpage}`;
  }
  return locationStr;
}

